package cc.wanforme.fsync.server;

import cc.wanforme.fsync.server.service.ITickTaskGroupService;
import cc.wanforme.fsync.server.service.ITickTaskService;
import cc.wanforme.fsync.task.JobWorker;
import cc.wanforme.st.server.vo.ResMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/server")
public class CronTaskController {

    private ITickTaskGroupService taskGroupService ;
    private ITickTaskService tickTaskService ;
    private ServerCenter serverCenter ;

    /** 手动触发定时任务 task */
    @GetMapping("/triggerNow")
    public ResMessage<Void> task(@RequestParam("id") Long taskId) {
        JobWorker jobWorker = new JobWorker();
        jobWorker.executeTask(taskId, taskGroupService, tickTaskService, serverCenter);
        return ResMessage.success();
    }

    @Autowired
    public void setTaskGroupService(ITickTaskGroupService taskGroupService) {
        this.taskGroupService = taskGroupService;
    }

    @Autowired
    public void setServerCenter(ServerCenter serverCenter) {
        this.serverCenter = serverCenter;
    }

    @Autowired
    public void setTickTaskService(ITickTaskService tickTaskService) {
        this.tickTaskService = tickTaskService;
    }

}
